﻿using System;
using System.Collections.Generic;
using System.IO;
using System.ServiceModel;
using System.Threading.Tasks;
using ClientProxies.ArchiveServiceReference;
using Common.Contracts;
using Exceptions;
using Serialization;

namespace ClientProxies
{
    public class FakeDocumentClient : ClientBase<IDocument>, IDocument
    {

         private readonly IServiceConfig _serviceConfig;

         public FakeDocumentClient(IServiceConfig serviceConfig)
         {
            this._serviceConfig = serviceConfig;
         }

        public DocumentSearchResultsData DocumentSearch(AuthenticationData authenticationData, int firstRow, int lastRow,
            string applicationId, string grid, int region, string search1, string search2, string search3, string search4,
            string search5, string search6, string search7, string search8, string search9, string search10)
        {

              if (!File.Exists(_serviceConfig.SearchByGridIdDataFilePath)) 
                throw new UnityException(" data file SearchByGridId.xml not found");

              //Populate data from xml file (  data )
              var result = SerializeHelper.DeSerializeObject<DocumentSearchResultsData>(_serviceConfig.SearchByGridIdDataFilePath);

            return result;
        }

        public DocumentSearchResultsIndexedData DocumentSearchMapVerbose(AuthenticationData authenticationData, int firstRow,
            int lastRow, int region, DateTime? startDate, DateTime? endDate, List<IndexNameCriteriaData> searchCriteriaList)
        {
            //String dataFilePath = Path.Combine(this.DataFolder, "SearchByParams.xml");

            if (!File.Exists(_serviceConfig.SearchByParamsDataFilePath)) 
                throw new UnityException(" data file for SearchByParams.xml not found");

            //Populate data from xml file (  data )
            var result = SerializeHelper.DeSerializeObject<DocumentSearchResultsIndexedData>(_serviceConfig.SearchByParamsDataFilePath);

            return result;
        }

        public byte[] GetDocument(AuthenticationData authenticationData, string id)
        {


            if (!File.Exists(_serviceConfig.SamplePdfFilePath)) 
                throw new UnityException("Fake data file SamplePdf not found");

            return File.ReadAllBytes(_serviceConfig.SamplePdfFilePath);
        }

        #region Not Implemented Methods

        public DocumentSearchResultsData DocumentSearchAll(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexSearchCriteraData> indexSearchCritera)
        {
            throw new NotImplementedException();
        }



        public DocumentSearchResultsIndexedData DocumentSearchAllVerbose(AuthenticationData authenticationData, int firstRow,
            int lastRow, int region, DateTime? startDate, DateTime? endDate, List<IndexSearchCriteraData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }



        public DocumentSearchResultsData DocumentSearchMap(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexNameCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        
        public DocumentSearchResultsData DocumentSearchMulti(AuthenticationData authenticationData, int firstRow, int lastRow,
            int region, DateTime? startDate, DateTime? endDate, List<IndexIdCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }



        public DocumentSearchResultsIndexedData DocumentSearchMultiVerbose(AuthenticationData authenticationData, int firstRow,
            int lastRow, int region, DateTime? startDate, DateTime? endDate, List<IndexIdCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        public string GetDocumentCustomProperty(AuthenticationData authenticationData, string documentid, string key)
        {
            throw new NotImplementedException();
        }



        public ApplicationInfoData GetApplication(AuthenticationData authenticationData, string applicationId)
        {
            throw new NotImplementedException();
        }



        public DocumentSearchResultsData IndexAppSearch(AuthenticationData authenticationData, int firstRow, int lastRow,
            string search1)
        {
            throw new NotImplementedException();
        }

        #endregion 

        #region Async Methods - Not Implemented

        public Task<DocumentSearchResultsData> DocumentSearchAsync(AuthenticationData authenticationData, int firstRow, int lastRow, string applicationId,
            string grid, int region, string search1, string search2, string search3, string search4, string search5,
            string search6, string search7, string search8, string search9, string search10)
        {
            throw new NotImplementedException();
        }



        public Task<DocumentSearchResultsData> DocumentSearchAllAsync(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexSearchCriteraData> indexSearchCritera)
        {
            throw new NotImplementedException();
        }



        public Task<DocumentSearchResultsIndexedData> DocumentSearchAllVerboseAsync(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexSearchCriteraData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        public Task<DocumentSearchResultsData> DocumentSearchMapAsync(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexNameCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        public Task<DocumentSearchResultsIndexedData> DocumentSearchMapVerboseAsync(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexNameCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        public Task<DocumentSearchResultsData> DocumentSearchMultiAsync(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
           DateTime? startDate, DateTime? endDate, List<IndexIdCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        public Task<DocumentSearchResultsIndexedData> DocumentSearchMultiVerboseAsync(AuthenticationData authenticationData, int firstRow, int lastRow, int region,
            DateTime? startDate, DateTime? endDate, List<IndexIdCriteriaData> searchCriteriaList)
        {
            throw new NotImplementedException();
        }

        public Task<byte[]> GetDocumentAsync(AuthenticationData authenticationData, string id)
        {
            throw new NotImplementedException();
        }

        public Task<string> GetDocumentCustomPropertyAsync(AuthenticationData authenticationData, string documentid, string key)
        {
            throw new NotImplementedException();
        }

        public Task<ApplicationInfoData> GetApplicationAsync(AuthenticationData authenticationData, string applicationId)
        {
            throw new NotImplementedException();
        }

        public Task<DocumentSearchResultsData> IndexAppSearchAsync(AuthenticationData authenticationData, int firstRow, int lastRow, string search1)
        {
            throw new NotImplementedException();
        }
        #endregion

    }
}
